﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraTabbedMdi;
using DevExpress.XtraBars;

namespace TanHungLong
{
    public partial class FrmMain : DevExpress.XtraEditors.XtraForm
    {
        public RmsControl.TranspControl transpControl = new RmsControl.TranspControl();

        public FrmMain()
        {
            InitializeComponent();

            this.Shown += new EventHandler(FrmMain_Shown);

            this.Controls.Add(this.transpControl);
            this.transpControl.BackColor = Color.Transparent;
            this.transpControl.BackImage = null;
            this.transpControl.FillColor = Color.SteelBlue;//
            this.transpControl.GlassColor = Color.Transparent;
            this.transpControl.GlassMode = true;
            this.transpControl.LineWidth = 2;
            this.transpControl.Location = new Point(0, 0);
            this.transpControl.Name = "transpControl1";
            this.transpControl.Opacity = 50;
            this.transpControl.Size = new Size(5, 5);
            this.transpControl.TranspKey = Color.LightSlateGray;
            this.transpControl.Visible = false;
            this.transpControl.SendToBack();

            this.FormClosing += new FormClosingEventHandler(FrmMain_FormClosing);

            this.barButtonItemPhongBan.ItemClick += new ItemClickEventHandler(barButtonItemPhongBan_ItemClick);
            this.barButtonItemDanhMuc.ItemClick += new ItemClickEventHandler(barButtonItemDanhMuc_ItemClick);
            this.barButtonItemChucVu.ItemClick += new ItemClickEventHandler(barButtonItemChucVu_ItemClick);
            this.barButtonItemHoSoNhanVien.ItemClick += new ItemClickEventHandler(barButtonItemHoSoNhanVien_ItemClick);
            this.barButtonItemNgachBacLuong.ItemClick += new ItemClickEventHandler(barButtonItemNgachBacLuong_ItemClick);
            this.barButtonItemPhuCap.ItemClick += new ItemClickEventHandler(barButtonItemPhuCap_ItemClick);
            this.barButtonItemKhoanTru.ItemClick += new ItemClickEventHandler(barButtonItemKhoanTru_ItemClick);
            this.barButtonItemTamUngLuong.ItemClick += new ItemClickEventHandler(barButtonItemTamUngLuong_ItemClick);
            this.barButtonItemThietDatHeThong.ItemClick += new ItemClickEventHandler(barButtonItemThietDatHeThong_ItemClick);
            this.barButtonItemBangLuong.ItemClick += new ItemClickEventHandler(barButtonItemBangLuong_ItemClick);
            this.barButtonItemKhachHang.ItemClick += new ItemClickEventHandler(barButtonItemKhachHang_ItemClick);
            this.barButtonItemDanhMucNhaCungCap.ItemClick += new ItemClickEventHandler(barButtonItemDanhMucNhaCungCap_ItemClick);
            this.barButtonItemNhomMatHang.ItemClick += new ItemClickEventHandler(barButtonItemNhomMatHang_ItemClick);
            this.barButtonItemMatHang.ItemClick += new ItemClickEventHandler(barButtonItemMatHang_ItemClick);
            this.barButtonItemQuyDoiMatHang.ItemClick += new ItemClickEventHandler(barButtonItemQuyDoiMatHang_ItemClick);
            this.barButtonItemPhieuYeuCau.ItemClick += new ItemClickEventHandler(barButtonItemPhieuYeuCau_ItemClick);
            this.barButtonItemHoaDonBanHang.ItemClick += new ItemClickEventHandler(barButtonItemHoaDonBanHang_ItemClick);
        }

        private void FrmMain_Shown(object sender, EventArgs e)
        {
            Model.Session.thietDatBOCollection = Model.ThietDatBOCollection.GetThietDatBOCollection();
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (Model.Session.CloseIndex > 0)
                e.Cancel = true;
        }

        #region event
        private void barButtonItemBangLuong_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmBangLuong frm = new FrmBangLuong();
            CallForm(frm);
        }

        private void barButtonItemThietDatHeThong_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmThietDat frm = new FrmThietDat(this);
            frm.Show();
        }

        private void barButtonItemTamUngLuong_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmTamUngLuong frm = new FrmTamUngLuong();
            CallForm(frm);
        }

        private void barButtonItemKhoanTru_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmKhoanTru frm = new FrmKhoanTru();
            CallForm(frm);
        }

        private void barButtonItemPhuCap_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmPhuCap frm = new FrmPhuCap();
            CallForm(frm);
        }

        private void barButtonItemNgachBacLuong_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmNgachBacLuong frm = new FrmNgachBacLuong();
            CallForm(frm);
        }

        private void barButtonItemHoSoNhanVien_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmNhanVien frm = new FrmNhanVien(this);
            frm.Show();
        }

        private void barButtonItemDanhMuc_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmDanhMuc frm = new FrmDanhMuc();
            CallForm(frm);
        }

        private void barButtonItemPhongBan_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmPhongBan frm = new FrmPhongBan();
            CallForm(frm);
        }

        private void barButtonItemChucVu_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmChucVu frm = new FrmChucVu();
            CallForm(frm);
        }

        private void barButtonItemKhachHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmKhachHang frm = new FrmKhachHang();
            CallForm(frm);
        }

        private void barButtonItemDanhMucNhaCungCap_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmNhaCungCap frm = new FrmNhaCungCap();
            CallForm(frm);
        }

        private void barButtonItemNhomMatHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmNhomHang frm = new FrmNhomHang();
            CallForm(frm);
        }

        private void barButtonItemMatHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmMatHangGia frm = new FrmMatHangGia();
            CallForm(frm);
        }


        private void barButtonItemQuyDoiMatHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmMatHangQuyDoi frm = new FrmMatHangQuyDoi();
            CallForm(frm);
        }

        private void barButtonItemPhieuYeuCau_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmPhieuYeuCau frm = new FrmPhieuYeuCau();
            CallForm(frm);
        }

        private void barButtonItemHoaDonBanHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmHoaDonBan frm = new FrmHoaDonBan();
            CallForm(frm);
        }
        
        #endregion event

        #region function
        public void ShowBgr()
        {
            this.transpControl.Location = new Point(0, 0);
            this.transpControl.Size = new Size(this.Width, this.Height);
            this.transpControl.Visible = true;
            this.transpControl.BringToFront();
            this.Update();
        }

        public void HideBgr()
        {
            this.transpControl.Visible = false;
        }

        public void CallForm(Form frm)
        {
            foreach (XtraMdiTabPage xtraMdiTabPage in this.xtraTabbedMdiManager1.Pages)
            {
                if (xtraMdiTabPage.MdiChild.Name == frm.Name)
                {
                    this.xtraTabbedMdiManager1.SelectedPage = xtraMdiTabPage;
                    return;
                }
            }
            frm.MdiParent = this;
            frm.Show();
        }

        public void CallForm(Form frm, string title)
        {
            foreach (XtraMdiTabPage xtraMdiTabPage in this.xtraTabbedMdiManager1.Pages)
            {
                if (xtraMdiTabPage.MdiChild.Text == title)
                {
                    this.xtraTabbedMdiManager1.SelectedPage = xtraMdiTabPage;
                    return;
                }
            }
            frm.MdiParent = this;
            frm.Show();
        }
        #endregion function
    }
}